import UnityPy

file_map = {
    "WORD_Indx": "WORD_Indx",
    "WORD_Text": "WORD_Text",
}


def extract_file(src, dst):
    env = UnityPy.load(src)
    for obj in env.objects:
        if obj.type.name == "TextAsset":
            data = obj.read()
            target_name: str = data.name
            if not target_name in file_map.keys():
                continue
            print(data.name)
            with open(f"output/4_res/{file_map[target_name]}.txt", "rb") as f:
                data.script = f.read()
            data.save()
    with open(dst, "wb") as f:  # 其实就是拿到文件名 写入而已
        f.write(env.file.save())


extract_file("data/data.unity3d", "output/5_res/data.unity3d")
